#!/usr/bin/env bash

jailname=`echo $1 | sed 's/\./_/g'`
bootnode_addr=$2
helper_path="/tmp/meth/helper"

binpath="/usr/jail/sharedfs/usr/local/bin"

CMD="${binpath}/geth init ${helper_path}/geth-genesis.json && \
    ${binpath}/geth --v5disc --rpc --rpcaddr 0.0.0.0 --bootnodes ${bootnode_addr}"

if [[ 7 -eq $[$RANDOM % 10] ]]; then
    CMD=$CMD" --mine --miner.threads 1 --etherbase 0x7777777777777777777777777777777777777777"
fi

mkdir -p $binpath || exit 1

qjail start $jailname || exit 1
qjail console -c "$CMD;wait" $jailname || exit 1
